package mvv.learn.spring.controller;

import mvv.learn.spring.dto.response.ResResponse;
import mvv.learn.spring.services.elastic.IndexElasticsearchService;
import mvv.learn.spring.utitilies.AppParam;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Manh Vu
 */
@Controller
@RequestMapping(value = "/elasticsearch/index", method = { RequestMethod.GET, RequestMethod.POST }, produces = MediaType.APPLICATION_JSON_VALUE)
public class IndexDocumentController extends AbsController {
	private static final Logger log = LoggerFactory.getLogger(IndexDocumentController.class);

	@Autowired
	private IndexElasticsearchService indexElasticsearchService;

	@RequestMapping(value = "/employee")
	@ResponseBody
	public ResResponse indexEmployee() {
		ResResponse res = new ResResponse(AppParam.VAL_GOOD, null, null);
		try {
			res = indexElasticsearchService.indexEmployee();
		}catch (Exception e) {
			log.error(e.getMessage(), e);
			res = new ResResponse(AppParam.VAL_BAD, e.getMessage(), e);
		}
		return res;
	}
}
